{
  "name": "Case 51: SDS Risk Auditor - Intelligent Agent",
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.cloud.llamaindex.ai/api/v1/parsing/upload",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "55d33625-f6c2-416d-add4-3d6346fc6f27",
      "name": "Upload SDS to Parser",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -752,
        -16
      ]
    },
    {
      "parameters": {
        "amount": 25
      },
      "id": "9ee005d7-fa01-4d0b-a6b2-66a244d5fba4",
      "name": "Wait for SDS Parsing",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -560,
        -16
      ],
      "webhookId": "a05383c1-084b-45a0-a272-62c2e24ec6f0"
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload SDS to Parser\"].json[\"id\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "0376c0fb-b707-46c9-8fd7-ca335628a9e8",
      "name": "Check Parsing Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -400,
        -16
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "SUCCESS",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "SUCCESS"
            },
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "PENDING",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "PENDING"
            }
          ]
        },
        "options": {}
      },
      "id": "f88c0734-a101-466e-9741-453f812f0e1b",
      "name": "Status Router",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        -256,
        -16
      ]
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload SDS to Parser\"].json[\"id\"] }}/result/markdown",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "4f03bf5e-176f-4bf2-96b3-9d0266e70168",
      "name": "Get Parsed SDS Data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -48,
        -128
      ]
    },
    {
      "parameters": {
        "text": "={{ $json.markdown }}",
        "attributes": {
          "attributes": [
            {
              "name": "Product_Name",
              "description": "Complete chemical name including concentration percentage"
            },
            {
              "name": "CAS_Number",
              "description": "CAS registry number in format XXXX-XX-X"
            },
            {
              "name": "Chemical_Formula",
              "description": "Molecular formula if available"
            },
            {
              "name": "Manufacturer",
              "description": "Manufacturing company name"
            },
            {
              "name": "GHS_Category",
              "description": "Highest GHS severity category number only: 1, 2, 3, or 4"
            },
            {
              "name": "Hazard_Level",
              "description": "Primary hazard type: FATAL / SEVERE_CORROSIVE / TOXIC / HARMFUL / IRRITANT / MINIMAL"
            },
            {
              "name": "Hazard_Statements",
              "description": "All H-statements mentioned (comma separated, e.g., H300, H310, H314)"
            },
            {
              "name": "PPE_Level",
              "description": "LEVEL_A / LEVEL_B / LEVEL_C / LEVEL_D"
            },
            {
              "name": "PPE_Details",
              "description": "Specific PPE equipment required (gloves type, respirator, suit, etc.)"
            },
            {
              "name": "Storage_Temperature",
              "description": "Required storage temperature range with units"
            },
            {
              "name": "Storage_Container_Type",
              "description": "Required container material (HDPE, PFA, Glass, etc.)"
            },
            {
              "name": "Storage_Incompatibles",
              "description": "Materials to segregate from (metals, acids, bases, etc.)"
            },
            {
              "name": "Ventilation_Required",
              "description": "YES or NO - is dedicated ventilation/fume extraction required"
            },
            {
              "name": "Secondary_Containment",
              "description": "YES or NO - is secondary containment required"
            },
            {
              "name": "Exposure_Limit_OSHA",
              "description": "OSHA PEL value with units (ppm or mg/m³)"
            },
            {
              "name": "Emergency_First_Aid_Skin",
              "description": "Critical first aid steps for skin contact"
            },
            {
              "name": "Emergency_First_Aid_Inhalation",
              "description": "Critical first aid steps for inhalation"
            },
            {
              "name": "Special_Antidote",
              "description": "Any specific antidote required (e.g., calcium gluconate) or NONE"
            },
            {
              "name": "UN_Number",
              "description": "UN transport number (e.g., UN1790)"
            },
            {
              "name": "Transport_Hazard_Class",
              "description": "DOT/UN hazard class (e.g., 8 - Corrosive)"
            },
            {
              "name": "Packing_Group",
              "description": "Packing group: I, II, or III"
            },
            {
              "name": "Training_Required",
              "description": "Specific training requirements mentioned"
            },
            {
              "name": "Medical_Surveillance",
              "description": "Any medical monitoring requirements (YES or NO)"
            },
            {
              "name": "Waste_Disposal_Code",
              "description": "Hazardous waste code if mentioned"
            }
          ]
        },
        "options": {}
      },
      "id": "7ddd3d30-d178-4d55-89ef-836baa0a22b8",
      "name": "Extract SDS Intelligence",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        96,
        -128
      ]
    },
    {
      "parameters": {
        "jsCode": "const extracted = $node[\"Extract SDS Intelligence\"].json.output;\n\n// ===== RISK SCORING ENGINE =====\n\nlet riskScore = 0;\n\n// 1. HAZARD LEVEL SCORING (40 points max)\nconst hazardLevel = extracted.Hazard_Level.toUpperCase();\nif (hazardLevel.includes('FATAL')) {\n  riskScore += 40;\n} else if (hazardLevel.includes('SEVERE') || hazardLevel.includes('CORROSIVE')) {\n  riskScore += 35;\n} else if (hazardLevel.includes('TOXIC')) {\n  riskScore += 25;\n} else if (hazardLevel.includes('HARMFUL')) {\n  riskScore += 15;\n} else if (hazardLevel.includes('IRRITANT')) {\n  riskScore += 8;\n} else {\n  riskScore += 3;\n}\n\n// 2. PPE COMPLEXITY SCORING (30 points max)\nconst ppeLevel = extracted.PPE_Level.toUpperCase();\nif (ppeLevel.includes('LEVEL_A') || ppeLevel.includes('SCBA')) {\n  riskScore += 30;\n} else if (ppeLevel.includes('LEVEL_B')) {\n  riskScore += 22;\n} else if (ppeLevel.includes('LEVEL_C')) {\n  riskScore += 12;\n} else {\n  riskScore += 5;\n}\n\n// 3. STORAGE COMPLEXITY SCORING (30 points max)\nlet storageScore = 0;\n\n// Temperature control needed\nconst storageTemp = extracted.Storage_Temperature;\nif (storageTemp && !storageTemp.includes('NOT_FOUND')) {\n  if (storageTemp.includes('Cryogenic') || storageTemp.includes('-')) {\n    storageScore += 10;\n  } else if (storageTemp.match(/\\d+/)) {\n    storageScore += 7;\n  }\n}\n\n// Ventilation required\nif (extracted.Ventilation_Required === 'YES') {\n  storageScore += 10;\n}\n\n// Secondary containment\nif (extracted.Secondary_Containment === 'YES') {\n  storageScore += 5;\n}\n\n// Incompatibility complexity\nconst incompatibles = extracted.Storage_Incompatibles;\nif (incompatibles && incompatibles.length > 20) {\n  storageScore += 5;\n}\n\nriskScore += Math.min(storageScore, 30);\n\n// ===== RISK LEVEL DETERMINATION =====\nlet riskLevel = '';\nif (riskScore >= 76) {\n  riskLevel = 'CRITICAL';\n} else if (riskScore >= 51) {\n  riskLevel = 'HIGH';\n} else if (riskScore >= 26) {\n  riskLevel = 'MEDIUM';\n} else {\n  riskLevel = 'LOW';\n}\n\n// ===== PRIORITY ASSIGNMENT =====\nlet priority = '';\nif (riskScore >= 76) {\n  priority = 'P0';\n} else if (riskScore >= 51) {\n  priority = 'P1';\n} else if (riskScore >= 26) {\n  priority = 'P2';\n} else {\n  priority = 'P3';\n}\n\n// ===== HANDLING PROTOCOL GENERATION =====\nlet handlingProtocol = '';\nif (riskLevel === 'CRITICAL') {\n  handlingProtocol = 'RESTRICTED ACCESS: Hazmat team only. Full Level A PPE mandatory. Emergency response team on standby. Store in dedicated isolation zone with 24/7 monitoring.';\n} else if (riskLevel === 'HIGH') {\n  handlingProtocol = 'CONTROLLED ACCESS: Certified personnel only. Level B/C PPE required. Enhanced ventilation mandatory. Store in hazmat zone with daily inspections.';\n} else if (riskLevel === 'MEDIUM') {\n  handlingProtocol = 'STANDARD PROTOCOLS: Trained staff with appropriate PPE. Regular safety audits. Store in designated chemical area with proper signage.';\n} else {\n  handlingProtocol = 'ROUTINE HANDLING: Basic safety training sufficient. Standard PPE adequate. Normal storage with periodic checks.';\n}\n\n// ===== TRAINING REQUIREMENTS =====\nlet trainingRequired = '';\nif (riskLevel === 'CRITICAL' || riskLevel === 'HIGH') {\n  trainingRequired = 'MANDATORY: Hazmat certification, Emergency response training, Annual medical surveillance, Quarterly refresher courses';\n} else if (riskLevel === 'MEDIUM') {\n  trainingRequired = 'REQUIRED: Chemical safety training, PPE usage certification, Annual refresher';\n} else {\n  trainingRequired = 'STANDARD: Basic chemical handling orientation, PPE awareness';\n}\n\n// ===== COMPLIANCE CHECK =====\nlet complianceStatus = '';\nconst warehouseZone = 'Chemical Zone'; // Warehouse location from form\n\nif (riskLevel === 'CRITICAL' && !warehouseZone.includes('Hazmat')) {\n  complianceStatus = 'NON_COMPLIANT: CRITICAL chemical requires Hazmat Zone storage';\n} else if (riskLevel === 'HIGH' && warehouseZone.includes('General')) {\n  complianceStatus = 'NON_COMPLIANT: HIGH risk chemical unsuitable for general storage';\n} else if (extracted.Storage_Temperature !== 'NOT_FOUND' && !warehouseZone.includes('Climate')) {\n  complianceStatus = 'WARNING: Temperature control required but warehouse not climate-controlled';\n} else {\n  complianceStatus = 'COMPLIANT';\n}\n\n// ===== WAREHOUSE ZONE RECOMMENDATION =====\nlet recommendedZone = '';\nif (riskLevel === 'CRITICAL') {\n  recommendedZone = 'Warehouse C - Hazmat Zone (Isolation Required)';\n} else if (riskLevel === 'HIGH') {\n  recommendedZone = 'Warehouse C - Hazmat Zone';\n} else if (extracted.Storage_Temperature !== 'NOT_FOUND') {\n  recommendedZone = 'Warehouse B - Climate Controlled';\n} else if (warehouseZone.includes('Flammable') && extracted.Transport_Hazard_Class.includes('Flammable')) {\n  recommendedZone = 'Warehouse D - Flammables';\n} else {\n  recommendedZone = 'Warehouse A - General Storage';\n}\n\n// ===== GENERATE UNIQUE SDS ID =====\nconst timestamp = new Date().toISOString().replace(/[-:]/g, '').split('.')[0];\nconst sdsId = `SDS-${timestamp}-${extracted.CAS_Number.replace(/-/g, '')}`;\n\n// ===== RETURN STRUCTURED DATA =====\nreturn {\n  SDS_ID: sdsId,\n  Upload_Date: new Date().toISOString().split('T')[0],\n  Chemical_Name: extracted.Product_Name,\n  CAS_Number: extracted.CAS_Number,\n  GHS_Category: `Category ${extracted.GHS_Category}`,\n  Hazard_Level: extracted.Hazard_Level,\n  PPE_Required: `${extracted.PPE_Level}: ${extracted.PPE_Details}`,\n  Storage_Requirements: `Temp: ${extracted.Storage_Temperature}, Container: ${extracted.Storage_Container_Type}, Ventilation: ${extracted.Ventilation_Required}`,\n  Risk_Score: riskScore,\n  Risk_Level: riskLevel,\n  Priority: priority,\n  Handling_Protocol: handlingProtocol,\n  Training_Required: trainingRequired,\n  Compliance_Status: complianceStatus,\n  Warehouse_Zone: recommendedZone,\n  \n  // Pass through for email\n  _full_sds_data: extracted,\n};"
      },
      "id": "c71eb3b4-8ddb-4bb1-9698-61cce8d14e59",
      "name": "Risk Assessment Engine",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        384,
        -128
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "19MJRoSmKsxlrqRfTgrc91eEskq0txFU6lrE5wemHG-s",
          "mode": "list",
          "cachedResultName": "Case 51 - Safety Data Sheet Log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19MJRoSmKsxlrqRfTgrc91eEskq0txFU6lrE5wemHG-s/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19MJRoSmKsxlrqRfTgrc91eEskq0txFU6lrE5wemHG-s/edit#gid=0"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [
            {
              "id": "SDS_ID",
              "displayName": "SDS_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Upload_Date",
              "displayName": "Upload_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Chemical_Name",
              "displayName": "Chemical_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "CAS_Number",
              "displayName": "CAS_Number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "GHS_Category",
              "displayName": "GHS_Category",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Hazard_Level",
              "displayName": "Hazard_Level",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "PPE_Required",
              "displayName": "PPE_Required",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Storage_Requirements",
              "displayName": "Storage_Requirements",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Risk_Score",
              "displayName": "Risk_Score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Risk_Level",
              "displayName": "Risk_Level",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Priority",
              "displayName": "Priority",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Handling_Protocol",
              "displayName": "Handling_Protocol",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Training_Required",
              "displayName": "Training_Required",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Compliance_Status",
              "displayName": "Compliance_Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Warehouse_Zone",
              "displayName": "Warehouse_Zone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "9ac1f087-2348-4802-a8e4-832a029ad03a",
      "name": "Log to Audit Database",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        592,
        -128
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst sds = data._full_sds_data;\n\nconst emailSubject = `🚨 ${data.Priority} - ${data.Risk_Level} HAZARD: ${data.Chemical_Name}`;\n\nconst emailBody = `\n<!DOCTYPE html>\n<html>\n<head>\n<style>\nbody { font-family: 'Segoe UI', sans-serif; line-height: 1.6; color: #1f2937; max-width: 900px; margin: 0 auto; padding: 20px; background: #f9fafb; }\n.container { background: white; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }\n.header { background: ${data.Risk_Level === 'CRITICAL' ? 'linear-gradient(135deg, #b91c1c 0%, #7f1d1d 100%)' : 'linear-gradient(135deg, #ea580c 0%, #c2410c 100%)'}; color: white; padding: 30px; }\n.header h1 { margin: 0; font-size: 26px; font-weight: 700; }\n.header .subtitle { margin: 8px 0 0 0; opacity: 0.95; font-size: 15px; }\n.alert-banner { background: ${data.Risk_Level === 'CRITICAL' ? '#fee2e2' : '#fed7aa'}; border-left: 5px solid ${data.Risk_Level === 'CRITICAL' ? '#dc2626' : '#ea580c'}; padding: 20px; margin: 20px; border-radius: 6px; }\n.alert-banner strong { font-size: 16px; display: block; margin-bottom: 8px; color: ${data.Risk_Level === 'CRITICAL' ? '#991b1b' : '#9a3412'}; }\n.risk-badge { display: inline-block; padding: 6px 16px; border-radius: 20px; font-size: 13px; font-weight: 700; text-transform: uppercase; background: ${data.Risk_Level === 'CRITICAL' ? '#dc2626' : '#ea580c'}; color: white; margin-left: 10px; }\n.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; background: #f9fafb; }\n.metric-card { background: white; padding: 20px; border-radius: 8px; border: 2px solid #e5e7eb; text-align: center; }\n.metric-label { font-size: 12px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 8px; font-weight: 600; }\n.metric-value { font-size: 28px; font-weight: 700; color: ${data.Risk_Level === 'CRITICAL' ? '#dc2626' : '#ea580c'}; }\n.section { padding: 25px; border-bottom: 1px solid #e5e7eb; }\n.section h2 { margin: 0 0 18px 0; font-size: 20px; color: #111827; border-left: 4px solid ${data.Risk_Level === 'CRITICAL' ? '#dc2626' : '#ea580c'}; padding-left: 12px; }\n.data-grid { display: grid; grid-template-columns: 200px 1fr; gap: 12px; }\n.data-label { font-weight: 600; color: #4b5563; }\n.data-value { color: #1f2937; }\n.warning-box { background: #fffbeb; border: 2px solid #fbbf24; border-radius: 8px; padding: 20px; margin: 20px; }\n.warning-box h3 { margin: 0 0 12px 0; color: #92400e; font-size: 18px; }\n.protocol-box { background: #eff6ff; border: 2px solid #3b82f6; border-radius: 8px; padding: 20px; margin: 20px; }\n.protocol-box h3 { margin: 0 0 15px 0; color: #1e40af; font-size: 18px; }\n.protocol-item { padding: 12px 0; padding-left: 30px; position: relative; border-bottom: 1px solid #dbeafe; }\n.protocol-item:last-child { border-bottom: none; }\n.protocol-item:before { content: \"✓\"; position: absolute; left: 0; color: #3b82f6; font-weight: bold; font-size: 18px; }\n.emergency-box { background: #fef2f2; border: 3px solid #dc2626; border-radius: 8px; padding: 20px; margin: 20px; }\n.emergency-box h3 { margin: 0 0 15px 0; color: #991b1b; font-size: 18px; }\n.ppe-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin: 15px 0; }\n.ppe-item { background: #f3f4f6; padding: 15px; border-radius: 6px; border-left: 4px solid #6b7280; }\n.footer { padding: 20px; background: #f9fafb; text-align: center; font-size: 13px; color: #6b7280; border-top: 2px solid #e5e7eb; }\n.cta-button { display: inline-block; background: #3b82f6; color: white; padding: 14px 28px; border-radius: 8px; text-decoration: none; font-weight: 600; margin: 15px 0; }\n</style>\n</head>\n<body>\n<div class=\"container\">\n\n<div class=\"header\">\n<h1>⚠️ ${data.Risk_Level} CHEMICAL HAZARD ALERT</h1>\n<p class=\"subtitle\">SDS Risk Assessment | ID: ${data.SDS_ID}</p>\n<span class=\"risk-badge\">PRIORITY ${data.Priority}</span>\n</div>\n\n<div class=\"alert-banner\">\n<strong>🚨 ${data.Risk_Level === 'CRITICAL' ? 'IMMEDIATE ACTION REQUIRED - LIFE SAFETY CRITICAL' : 'URGENT REVIEW REQUIRED - HIGH HAZARD CHEMICAL'}</strong>\nA ${data.Risk_Level.toLowerCase()} risk chemical has been uploaded to the warehouse system requiring immediate safety protocols and specialized handling procedures.\n</div>\n\n<div class=\"metrics\">\n<div class=\"metric-card\">\n<div class=\"metric-label\">Risk Score</div>\n<div class=\"metric-value\">${data.Risk_Score}/100</div>\n</div>\n<div class=\"metric-card\">\n<div class=\"metric-label\">GHS Category</div>\n<div class=\"metric-value\">${sds.GHS_Category}</div>\n</div>\n<div class=\"metric-card\">\n<div class=\"metric-label\">Hazard Level</div>\n<div class=\"metric-value\" style=\"font-size: 20px;\">${data.Hazard_Level}</div>\n</div>\n</div>\n\n<div class=\"section\">\n<h2>📋 Chemical Identification</h2>\n<div class=\"data-grid\">\n<div class=\"data-label\">Chemical Name:</div>\n<div class=\"data-value\"><strong>${data.Chemical_Name}</strong></div>\n<div class=\"data-label\">CAS Number:</div>\n<div class=\"data-value\">${data.CAS_Number}</div>\n<div class=\"data-label\">Manufacturer:</div>\n<div class=\"data-value\">${sds.Manufacturer}</div>\n<div class=\"data-label\">Upload Date:</div>\n<div class=\"data-value\">${data.Upload_Date}</div>\n<div class=\"data-label\">Uploaded By:</div>\n<div class=\"data-value\">\"Chemical Engineer\"</div>\n<div class=\"data-label\">Current Location:</div>\n<div class=\"data-value\">\"Chemical Warehouse\"</div>\n</div>\n</div>\n\n<div class=\"section\">\n<h2>⚠️ Hazard Assessment</h2>\n<div class=\"data-grid\">\n<div class=\"data-label\">GHS Classification:</div>\n<div class=\"data-value\">${data.GHS_Category}</div>\n<div class=\"data-label\">Hazard Statements:</div>\n<div class=\"data-value\">${sds.Hazard_Statements}</div>\n<div class=\"data-label\">Primary Hazard:</div>\n<div class=\"data-value\"><strong style=\"color: #dc2626;\">${data.Hazard_Level}</strong></div>\n<div class=\"data-label\">Transport Class:</div>\n<div class=\"data-value\">${sds.Transport_Hazard_Class} (${sds.UN_Number})</div>\n<div class=\"data-label\">Packing Group:</div>\n<div class=\"data-value\">Group ${sds.Packing_Group}</div>\n</div>\n</div>\n\n<div class=\"emergency-box\">\n<h3>🚑 EMERGENCY RESPONSE - CRITICAL</h3>\n<p><strong>Skin Contact:</strong> ${sds.Emergency_First_Aid_Skin}</p>\n<p><strong>Inhalation:</strong> ${sds.Emergency_First_Aid_Inhalation}</p>\n${sds.Special_Antidote !== 'NONE' ? `<p style=\"background: #fee2e2; padding: 10px; border-radius: 4px; margin-top: 10px;\"><strong>⚕️ SPECIAL ANTIDOTE REQUIRED:</strong> ${sds.Special_Antidote}</p>` : ''}\n<p style=\"margin-top: 15px; font-weight: 600;\">☎️ Emergency Hotline: Immediately call poison control and on-site safety officer</p>\n</div>\n\n<div class=\"section\">\n<h2>🛡️ Personal Protective Equipment</h2>\n<div class=\"ppe-grid\">\n<div class=\"ppe-item\">\n<strong>PPE Level Required:</strong><br>\n${sds.PPE_Level}\n</div>\n<div class=\"ppe-item\">\n<strong>Specific Equipment:</strong><br>\n${sds.PPE_Details}\n</div>\n</div>\n<p style=\"margin-top: 15px; padding: 12px; background: #fef3c7; border-left: 4px solid #f59e0b; border-radius: 4px;\"><strong>⚠️ Note:</strong> All personnel must be fitted and trained on required PPE before handling this chemical.</p>\n</div>\n\n<div class=\"section\">\n<h2>📦 Storage Requirements</h2>\n<div class=\"data-grid\">\n<div class=\"data-label\">Temperature:</div>\n<div class=\"data-value\">${sds.Storage_Temperature}</div>\n<div class=\"data-label\">Container Type:</div>\n<div class=\"data-value\">${sds.Storage_Container_Type}</div>\n<div class=\"data-label\">Ventilation:</div>\n<div class=\"data-value\">${sds.Ventilation_Required === 'YES' ? '<strong style=\"color: #dc2626;\">MANDATORY - Fume extraction required</strong>' : 'Standard'}</div>\n<div class=\"data-label\">Secondary Containment:</div>\n<div class=\"data-value\">${sds.Secondary_Containment === 'YES' ? '<strong style=\"color: #dc2626;\">REQUIRED</strong>' : 'Not required'}</div>\n<div class=\"data-label\">Incompatible Materials:</div>\n<div class=\"data-value\" style=\"color: #dc2626;\"><strong>SEGREGATE FROM:</strong> ${sds.Storage_Incompatibles}</div>\n</div>\n</div>\n\n${data.Compliance_Status !== 'COMPLIANT' ? `\n<div class=\"warning-box\">\n<h3>⚠️ COMPLIANCE WARNING</h3>\n<p><strong>Status:</strong> ${data.Compliance_Status}</p>\n<p><strong>Current Location:</strong> \"Chemical Warehouse\"</p>\n<p><strong>Recommended Zone:</strong> ${data.Warehouse_Zone}</p>\n<p style=\"margin-top: 12px; font-weight: 600;\">ACTION REQUIRED: Chemical must be relocated to appropriate storage zone immediately.</p>\n</div>\n` : ''}\n\n<div class=\"protocol-box\">\n<h3>📋 MANDATORY HANDLING PROTOCOLS</h3>\n<div class=\"protocol-item\">${data.Handling_Protocol}</div>\n<div class=\"protocol-item\"><strong>Training:</strong> ${data.Training_Required}</div>\n<div class=\"protocol-item\"><strong>Exposure Monitoring:</strong> OSHA PEL: ${sds.Exposure_Limit_OSHA} - Air monitoring required</div>\n${sds.Medical_Surveillance === 'YES' ? '<div class=\"protocol-item\"><strong>Medical Surveillance:</strong> Mandatory health monitoring program for exposed workers</div>' : ''}\n<div class=\"protocol-item\"><strong>Waste Disposal:</strong> Code ${sds.Waste_Disposal_Code} - Licensed hazmat contractor only</div>\n</div>\n\n<div style=\"text-align: center; padding: 25px;\">\n<a href=\"https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID\" class=\"cta-button\">📊 View Full SDS Audit Database</a>\n</div>\n\n<div class=\"section\">\n<h2>📈 Risk Assessment Summary</h2>\n<div class=\"data-grid\">\n<div class=\"data-label\">Overall Risk Score:</div>\n<div class=\"data-value\"><strong style=\"font-size: 20px; color: #dc2626;\">${data.Risk_Score}/100</strong></div>\n<div class=\"data-label\">Risk Classification:</div>\n<div class=\"data-value\"><strong>${data.Risk_Level}</strong></div>\n<div class=\"data-label\">Action Priority:</div>\n<div class=\"data-value\"><strong>${data.Priority}</strong> - ${data.Priority === 'P0' ? 'Implement within 4 hours' : 'Implement within 24 hours'}</div>\n<div class=\"data-label\">Recommended Zone:</div>\n<div class=\"data-value\">${data.Warehouse_Zone}</div>\n</div>\n</div>\n\n<div class=\"footer\">\n<p><strong>Warehouse Safety Management System - SDS Risk Auditor</strong></p>\n<p>This is an automated safety alert generated by AI-powered SDS analysis</p>\n<p>Report Generated: ${new Date().toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' })}</p>\n<p style=\"margin-top: 10px; font-weight: 600;\">For immediate safety concerns, contact: Safety Officer +91-XXXX-XXXXXX</p>\n</div>\n\n</div>\n</body>\n</html>\n`;\n\nreturn {\n  emailSubject: emailSubject,\n  emailBody: emailBody,\n  warehouseManager: 'warehouse.manager@company.com'\n};"
      },
      "id": "e43cbf7e-fedb-41eb-b150-4534247ddbfe",
      "name": "Build Safety Alert Email",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        784,
        -128
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.warehouseManager }}",
        "subject": "={{ $json.emailSubject }}",
        "message": "={{ $json.emailBody }}",
        "options": {}
      },
      "id": "06a29c57-415b-4d74-9c6b-766a16f59882",
      "name": "Send Safety Alert via Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        976,
        -128
      ],
      "webhookId": "0a4281a8-c149-4f49-9a1b-495c7ad4dd20",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "b022dfe0-3766-48b9-97d5-728190203dab",
      "name": "GPT-4o Mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        192,
        80
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "id": "9b13e2c1-73bb-4afa-9532-87b16dc30573",
      "name": "Download Report PDF",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -928,
        -16
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "1qmt3_Cx66YFppgAI2Vzx-ikrVCWpTBNg",
          "mode": "list",
          "cachedResultName": "Case 51 - Safety Reports Folder",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1qmt3_Cx66YFppgAI2Vzx-ikrVCWpTBNg"
        },
        "event": "fileCreated",
        "options": {}
      },
      "id": "228baf1b-8b78-4cb9-b71f-e1cfad907857",
      "name": "Watch Safety Reports Folder",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -1104,
        -16
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Upload SDS to Parser": {
      "main": [
        [
          {
            "node": "Wait for SDS Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for SDS Parsing": {
      "main": [
        [
          {
            "node": "Check Parsing Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Parsing Status": {
      "main": [
        [
          {
            "node": "Status Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Status Router": {
      "main": [
        [
          {
            "node": "Get Parsed SDS Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for SDS Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Parsed SDS Data": {
      "main": [
        [
          {
            "node": "Extract SDS Intelligence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract SDS Intelligence": {
      "main": [
        [
          {
            "node": "Risk Assessment Engine",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Risk Assessment Engine": {
      "main": [
        [
          {
            "node": "Log to Audit Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Audit Database": {
      "main": [
        [
          {
            "node": "Build Safety Alert Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Safety Alert Email": {
      "main": [
        [
          {
            "node": "Send Safety Alert via Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4o Mini": {
      "ai_languageModel": [
        [
          {
            "node": "Extract SDS Intelligence",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Download Report PDF": {
      "main": [
        [
          {
            "node": "Upload SDS to Parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Watch Safety Reports Folder": {
      "main": [
        [
          {
            "node": "Download Report PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ed4b84ed-4ef8-40bb-b7e0-7c81e765dce2",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "FspNHVTyxmL16aFd",
  "tags": []
}